package Dinamica;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class robbery {

	static class info {
		public int t;
		public int c1;
		public int f1;
		public int c2;
		public int f2;

		public info(int t, int c1, int f1, int f2, int c2) {
			this.t = t;
			this.c1 = c1;
			this.c2 = c2;
			this.f1 = f1;
			this.f2 = f2;
		}
	}

	public static void llenar(int[][] memo, info in) {
		for (int i = in.f1; i <= in.f2; i++) {
			for (int j = in.c1; j <= in.c2; j++) {
				if (i == in.f1 || i == in.f2 || j == in.c1 || j == in.c2) {
					memo[i][j] = 2;
				} else {
					memo[i][j] = 1;
				}
			}
		}
	}

	public static void main(String[] args) throws Throwable {
		BufferedReader br = new BufferedReader(new FileReader("robbery.in"));
		String line = null;
		while ((line = br.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(line);
			int f = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			int t = Integer.parseInt(st.nextToken());

			Comparator<info> comparator = new Comparator<info>() {
				@Override
				public int compare(info o1, info o2) {
					// TODO Auto-generated method stub
					return o2.t - o1.t;
				}
			};
			List<info> l = new ArrayList<info>();
			for (int i = 0; i < t; i++) {
				String u=br.readLine();
				System.out.println(br.readLine());
				st = new StringTokenizer(u);
				
				l.add(new info(Integer.parseInt(st.nextToken()), Integer
						.parseInt(st.nextToken()), Integer.parseInt(st
						.nextToken()), Integer.parseInt(st.nextToken()),
						Integer.parseInt(st.nextToken())));
			}
			Collections.sort(l, comparator);
			int memo[][] = new int[f][c];
			for (info it : l) {
				llenar(memo, it);
				for (int i = 0; i < memo.length; i++) {
					System.out.println(Arrays.toString(memo[i]));
				}
			}
			

		}
	}

}
